package br.ucb.antares.HIB;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.ucb.antares.entidade.Venda;
import br.ucb.antares.interfaces.HIB;
import br.ucb.antares.log4j.VendaLog;

public class VendaHIB implements HIB<Venda> {
	
	public void salvar(Venda venda){
		Session session = HibernateUtil.getSession();
		Transaction transaction = session.beginTransaction();
		session.saveOrUpdate(venda);
		transaction.commit();
		session.close();
	}
	
	public void excluir (Venda venda){
		Session session = HibernateUtil.getSession();
	    Transaction transaction = session.beginTransaction();
	    session.delete(venda);
	    transaction.commit();
	session.close();
	}

	@SuppressWarnings("unchecked")
	public List<Venda>  listar() {
		Session session = HibernateUtil.getSession();
	    try {
	      return session.createCriteria(Venda.class).list();
	    } finally {
	      session.close();
	    }
	}
	public Venda consultar(long id) {
	    Session session = HibernateUtil.getSession();
	    try {
	    	Venda venda = (Venda) session.get(Venda.class, id);
	      return venda;
	    } finally {
	      session.close();
	    }
	}


}
